package IC.AST;

import IC.SemanticChecks.PropagatingVisitor;
import IC.Symbols.SymbolTable;
import IC.Types.Type;

/**
 * Abstract AST node base class.
 * 
 * @author Tovi Almozlino
 */
public abstract class ASTNode {

	private int line;
	private int order;
	private int label;
	
	/**
	 * Double dispatch method, to allow a visitor to visit a specific subclass.
	 * 
	 * @param visitor
	 *            The visitor.
	 * @return A value propagated by the visitor.
	 */
	public abstract Object accept(Visitor visitor);
	public abstract <DownType, UpType> UpType accept(PropagatingVisitor<DownType, UpType> visitor, DownType context);

	/** reference to symbol table of enclosing scope **/
	private SymbolTable enclosingScope;
	private IC.Types.Type nodeType;


	/**
	 * Constructs an AST node corresponding to a line number in the original
	 * code. Used by subclasses.
	 * 
	 * @param line
	 *            The line number.
	 */
	protected ASTNode(int line) {
		this.line = line;
	}

	public int getLine() {
		return line;
	}
	
	public int getOrder() {
		return order;
	}
	
	public void setOrder(int order){
		this.order = order;
	}
	
	/** returns symbol table of enclosing scope **/
	public SymbolTable getEnclosingScope() {
		return enclosingScope;
	}
	
	/** sets symbol table of enclosing scope **/
	public void setEnclosingScope(SymbolTable symbolTable) {
		this.enclosingScope = symbolTable;
	}
	
	/** returns symbol table of enclosing scope **/
	public Type getNodeType() {
		return nodeType;
	}
	
	/** sets symbol table of enclosing scope **/
	public void setNodeType(IC.Types.Type type) {
		this.nodeType = type;
	}

	public void setLabel(int label) {
		this.label = label;
	}
	
	public int getLabel() {
		return label;
	}

}
